﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ScoutOffice.DAL;
using System.Data.SqlClient;
using System.Configuration;
using ScoutOffice.BLL;

namespace ScoutOffice.UnitTests.DAL
{
    [TestFixture]
    public class ScoutManagerFixture
    {
        [Test]
        public void InsertScout()
        {
            ScoutManager.InsertScout(Guid.NewGuid(), "Joe", "Scout");

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ScoutOffice.DAL.Properties.Settings.SqlExpressConnectionString"].ConnectionString))
            {
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandText = "SELECT * FROM SCOUT";
                    conn.Open();
                    using (SqlDataReader reader = com.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read());
                        Assert.AreEqual("Joe", reader["FirstName"]);
                        Assert.AreEqual("Scout", reader["LastName"]);
                    }
                }
            }
        }

        [Test]
        public void FetchScoutByScoutId()
        {
            Guid scoutId = Guid.NewGuid();
            ScoutManager.InsertScout(scoutId, "Joe", "Scout");

            Scout s = ScoutManager.FetchScoutByScoutId(scoutId);
            
            Assert.IsNotNull(s);
            Assert.AreEqual("Joe", s.FirstName);
            Assert.AreEqual("Scout", s.LastName);
        }

        [Test]
        public void FetchScoutByScoutId_ScoutIdDNE()
        {
            Scout s = ScoutManager.FetchScoutByScoutId(Guid.NewGuid());
            Assert.IsNull(s);
        }
    }
}
